/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import static com.cxhd.lis.model.newmodel.LisProfiletest.lisProfiletestdao;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.cxhd.lis.model.newmodel.LisProfiletest;

/**
 *
 * @author cxhd
 */
@ControllerBind(controllerKey = "/view/lis/pro")
public class ProfiletestCtrl extends Controller{
     
    public void index(){
        render("/view/lis/yqbhsz.jsp");
    }
    
    public void getProfiletestList(){//没有详细的初始数据
//         renderJson(Db.use("mysql").find("select pr.PK,pr.PROFILENAME,pr.PROFILECODE,pr.PROFILEDESCRIBE,pr.EMERGENCY,pr.DATAWINDOWNAME,pr.INUREDATE,\n" +
//"pr.OPERATOR,pr.SECTION,pr.SAMPLETYPE,pr.BJMC,pr.DEFNOTE,pr.DEFHYXM,pr.DEFINPUT,pr.NOTES,pr.DEVICEID,pr.SECTION,pr.SAMPLETYPE,\n" +
//" (select de.DEVICENAME   from lis_deviceset de where de.DEVICEID=pr.DEVICEID) DEVICEID1,\n" +
//" (select ks.KSMC   from lis_ksdm ks where ks.KSDM=pr.SECTION) SECTION1,\n" +
//" (select sa.SAMPLEDESCRIBE  from lis_sampletype sa where sa.SAMPLETYPE=pr.SAMPLETYPE ) SAMPLETYPE1\n" +
//" from lis_profiletest pr where pr.section='3082'"));

             String sql="select pr.PK,pr.PROFILENAME,pr.PROFILECODE,pr.PROFILEDESCRIBE,pr.EMERGENCY,pr.DATAWINDOWNAME,pr.INUREDATE,\n" +
"pr.OPERATOR,pr.SECTION,pr.SAMPLETYPE,pr.BJMC,pr.DEFNOTE,pr.DEFHYXM,pr.DEFINPUT,pr.NOTES,pr.DEVICEID,pr.SECTION,pr.SAMPLETYPE,+\n" +
" (select de.DEVICENAME   from lis_deviceset de where de.DEVICEID=pr.DEVICEID) DEVICEID1, +\n" +
" (select ks.KSMC   from lis_ksdm ks where ks.KSDM=pr.SECTION) SECTION1, +\n" +
" (select sa.SAMPLEDESCRIBE  from lis_sampletype sa where sa.SAMPLETYPE=pr.SAMPLETYPE ) SAMPLETYPE1";
     String param="  from lis_profiletest pr where PROFILECODE like '%"+getPara("searchContent")+"%' or PROFILEDESCRIBE like '%"+getPara("searchContent")+"%'";
Page<Record> userPage = Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize",getParaToInt("pageSize")), sql, param);
renderJson(userPage);
//               String name= getPara("name2",null);
//               String param="";
//               if(name!=null){
//     param=" FROM lis_profiletest  where section='3082' and PROFILENAME like '%"+name+"%'";
//               }
//      sql=sql+param;
//       
//      renderJson( Db.use("mysql").find(sql));
      
//       Page<Record> userPage = Db.use("sqlserver").paginate(getParaToInt("currentPage", 1), getParaToInt("pageSize", 10), sql, param);
//        renderJson(userPage);
    } 
    //PROFILENAME PROFILECODE PROFILEDESCRIBE DEVICEID DATAWINDOWNAME SECTION SAMPLETYPE DEFINPUT BJMC DEFNOTE DEFHYXM NOTES
                            //
    public void addProfiletestList(){    
      new LisProfiletest().saveLisProfiletest(getPara("PROFILENAME"),getPara("PROFILECODE"),getPara("PROFILEDESCRIBE"),
            getPara("DEVICEID"),getPara("DATAWINDOWNAME"),getPara("SECTION"),getPara("SAMPLETYPE"),
            getPara("DEFINPUT"),getPara("BJMC"),getPara("DEFNOTE"),getPara("DEFHYXM"),getPara("NOTES"));
      renderText("true");
    }
    public void updateProfiletestList(){
     lisProfiletestdao.updateLisProfiletest(getPara("PK"),getPara("PROFILENAME"),getPara("PROFILECODE"),getPara("PROFILEDESCRIBE"),
            getPara("DEVICEID"),getPara("DATAWINDOWNAME"),getPara("SECTION"),getPara("SAMPLETYPE"),
            getPara("DEFINPUT"),getPara("BJMC"),getPara("DEFNOTE"),getPara("DEFHYXM"),getPara("NOTES"));
      renderText("true");
    }
    public void deleteProfiletestList(){
        lisProfiletestdao.deleteLisProfiletest(Integer.valueOf(getPara("pk")));
        renderText("true");
    }
    public void getLisDeviceset(){//检测仪器
        renderJson(Db.use("mysql").find("select DEVICEID,DEVICENAME   from lis_deviceset "));
    }
    public void getLisKsdm(){//科室
        renderJson(Db.use("mysql").find("select KSDM,KSMC   from lis_ksdm ")); 
    }
    public void getLisSampletype(){//样本类型
        renderJson(Db.use("mysql").find("select SAMPLETYPE,SAMPLEDESCRIBE,PY   from lis_sampletype "));
    }
    public void getLisHyxm(){//默认项目 不全
        renderJson(Db.use("mysql").find("select HYID,HYXM  from lis_hyxm  "));
    }
}
